package com.itheima.client.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheim.client.pojo.Order;
import com.itheim.client.pojo.OrderDetail;
import com.itheim.client.pojo.ShoppingCart;
import com.itheim.client.pojo.User;
import com.itheim.client.vo.AddressVo;
import com.itheim.client.vo.OrderDetailVo;
import com.itheim.client.vo.OrderVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author longbosheng
 * @Date 2022/6/18 20:56
 * @PackageName:com.itheima.mapper
 * @ClassName: OrderMapper
 * @Description: TODO
 * @Version 1.0
 */
@Mapper
public interface COrderMapper extends BaseMapper<Order> {
    /**
     * 按用户id清空购物车
     *
     * @param userId
     * @return
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    boolean clearShoppingCart(String userId);

    /**
     * 按照地址id查询信息
     *
     * @param order
     * @return
     */
    @Select("select * from address where id = #{addressBookId}")
    AddressVo selectAddressById(Order order);

    /**
     * 按照用户id查询购物车
     *
     * @param order
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> ShoppingCartInfo(Order order);

    /**
     * 添加信息到订单详情
     *
     * @param orderDetail
     * @return
     */
    @Insert("insert into order_detail values(#{id},)")
    boolean addOrderDetail(OrderDetail orderDetail);

    /**
     * 按用户id查询订单并分页
     *
     * @param offset
     * @param pageSize
     * @param userId
     * @return
     */
    @Select("select * from `order` where user_id = #{userId} limit #{offset},#{pageSize}")
    List<OrderVo> orderList(int offset, int pageSize, String userId);

    /**
     * 查询总条数
     *
     * @param userId
     * @return
     */
    @Select("select count(*) from `order` where user_id=#{userId}")
    int gettotal(String userId);

    /**
     * 按照订单id查询订单详情信息
     *
     * @param orderId
     * @return
     */
    @Select("select * from order_detail where order_id=#{orderId}")
    List<OrderDetailVo> detailList(String orderId);

    /**
     * 获取下单的用户信息
     * @return
     */
    @Select("select * from user  where id = #{id}")
    User selectOrderUser(String id);
}
